version: 2.1
jobs:
  build_clang:
    docker:
      - image: debian:11
    resource_class: medium
    steps:
      - checkout
      - run:
          name: "prepare & build"
          command: |
              apt-get update
              apt-get install -y cmake clang wx-common libwxgtk3.0-gtk3-dev wx3.0-headers libev-dev libboost-system-dev libboost-date-time-dev libboost-regex-dev libboost-program-options-dev
              cmake -S . -B build.release -DCMAKE_BUILD_TYPE=Release -DBUILD_THREAD=on -DBUILD_BOOST_ASIO=on -DBUILD_WX=on -DBUILD_EV=on -DBUILD_DOC=on -DBUILD_EXAMPLES=on -DCMAKE_CXX_FLAGS="-fsanitize=undefined -fsanitize=address -fno-omit-frame-pointer -Wall -Wextra -pedantic -Werror"
              cd build.release && make -j2 && ctest --output-on-failure .  && cd ..
              cmake -S . -B build.shared -DBUILD_SHARED_LIBS=on -DBUILD_THREAD=on -DBUILD_BOOST_ASIO=on -DBUILD_WX=on -DBUILD_EV=on -DBUILD_EXAMPLES=on
              cd build.shared && make -j2 && ctest --output-on-failure . && cd ..

  build_gcc:
    docker:
      - image: debian:10
    resource_class: medium
    steps:
      - checkout
      - run:
          name: "prepare & build"
          command: |
              apt-get update
              apt-get install -y cmake g++ git lcov wx-common libwxgtk3.0-gtk3-dev wx3.0-headers libev-dev libboost-system-dev libboost-date-time-dev libboost-regex-dev libboost-program-options-dev
              mkdir build
              cd build && cmake -DBUILD_DOC=on -DBUILD_THREAD=on -DBUILD_BOOST_ASIO=on -DBUILD_WX=on -DBUILD_EV=on -DBUILD_DOC=on -DCMAKE_CXX_FLAGS="-g -fprofile-arcs -ftest-coverage --coverage -Wall -Wextra -pedantic -Werror" ..
              make -j2
              lcov --directory . --zerocounters
              cd tests && ROTOR_INSPECT_DELIVERY=10 ctest --output-on-failure . && ROTOR_INSPECT_DELIVERY=1 ctest . && cd ..
              lcov --directory . --capture --output-file coverage.info
              lcov --remove coverage.info '*/tests/*' '*/examples/*'  '/usr/*' --output-file coverage.info.cleaned
              rm coverage.info
              genhtml -o coverage coverage.info.cleaned
              apt-get install -y curl
              bash <(curl -s https://codecov.io/bash) -X gcov

  build_gcc_thread_unsafe:
    docker:
      - image: debian:10
    resource_class: medium
    steps:
      - checkout
      - run:
          name: "prepare & build"
          command: |
              apt-get update
              apt-get install -y cmake g++ libev-dev libboost-system-dev libboost-date-time-dev libboost-regex-dev libboost-program-options-dev
              mkdir build
              cd build && cmake -DBUILD_DOC=on -DBUILD_THREAD=on -DBUILD_BOOST_ASIO=on -DBUILD_THREAD_UNSAFE=on -DBUILD_EV=on -DBUILD_DOC=on ..
              make -j2 && ctest .

  build_arm:
    machine:
      image: ubuntu-2004:202101-01
    resource_class: arm.medium
    steps:
      - checkout
      - run:
          name: "prepare & build"
          command: |
              sudo apt-get update
              sudo apt-get install -y cmake g++ libev-dev libboost-system-dev libboost-date-time-dev libboost-regex-dev libboost-program-options-dev
              mkdir build
              cd build && cmake -DBUILD_DOC=on -DBUILD_THREAD=on -DBUILD_BOOST_ASIO=on -DBUILD_EV=on ..
              make -j2 && ctest .

  build_conan:
    docker:
      - image: debian:10
    resource_class: medium
    steps:
      - checkout
      - run:
          name: "prepare & build"
          command: |
              apt-get update
              apt-get install -y cmake clang python3-pip
              pip3 install conan
              conan create conanfile.py rotor/0.20@


workflows:
  build-all-workflow:
    jobs:
      - build_gcc
      - build_gcc_thread_unsafe
      - build_clang
      - build_arm
      - build_conan
